const http = require('http')
const url = require('url')
const fs = require('fs')
const path = require('path')

const server = http.createServer((req,res)=>{
   console.log(req.url)
   res.setHeader('Content-Type','text/html;charset=utf8')
   if(req.url === '/'){
       let filePath = path.join(__dirname,'./views/index.html')
       fs.readFile(filePath,'utf8',(err,fileContent)=>{
        if(err){
            throw err
        }
        res.write(fileContent)
        res.end()
       })
    }else{
        res.setHeader('Content-Type','text/html;charset=utf8')
            let filePath = path.join(__dirname,'./views/404.html')
            fs.readFile(filePath,'utf8',(err,fileContent)=>{
                if(err){
                    throw err
                }
                res.write(fileContent)
                res.end()
            })
    }
})
server.listen(3000,()=>{
    console.log('server is running...')
})